/**
 * elancom Corporation copy right 2012 - 2015  
 *   
 * $Header: https://192.168.1.224/svn/elancom/product/elancom-platform/trunk/src/main/java/com/elancom/tools/Clazz2Json.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Id: Clazz2Json.java 1034 2012-07-02 03:09:12Z lanzhouxue $
 * $Author: lanzhouxue $
 * $Date: 2012-07-02 11:09:12 +0800 (Mon, 02 Jul 2012) $
 * $Revision: 1034 $
 */
package com.elancom.framework.commons.util;

import java.lang.reflect.Method;

/**
 * @author elancom
 * @date 2012-5-11
 */
public class Clazz2Json {
	/**
	 * 返回一个包含某些 Field 对象的数组，这些对象反映此 Class 对象所表示的类或接口的所有可访问公共字段。
	 * 
	 * @param clazz
	 * @return
	 */
	public static String c2j(Class<?> clazz) {
		if (clazz == null) {
			return null;
		}

		final StringBuilder sb = new StringBuilder();
		final Method[] methods = clazz.getMethods();

		sb.append("{");
		for (final Method m : methods) {
			String name = m.getName();
			if (name.startsWith("get")) {
				if ("getClass".equals(name)) {
					continue;
				}
				name = StringUtils.toFirstLower(name.substring(3, name.length()));
				sb.append("\"").append(name).append("\",");
			}
		}
		if (methods.length != 0) {
			sb.deleteCharAt(sb.length() - 1);
		}
		sb.append("}");

		return sb.toString();
	}
}
